package middleware

import (
	"github.com/gin-gonic/gin"
	"gitee.com/xiaofengfeng123/srv-paper-tape/api/response"
	"gitee.com/xiaofengfeng123/srv-paper-tape/errors"
	"gitee.com/xiaofengfeng123/srv-paper-tape/utils"
	"net/http"
)

// 从header获取Authorization
func JWT() gin.HandlerFunc {
	return func(c *gin.Context) {
		claims, err := utils.GetHeaderClaims(c)
		if err != nil {
			response.JSON(c,http.StatusForbidden,nil,errors.ErrForbidden)
			c.Abort()
			return
		}
		c.Set("id",claims.Uid)
		c.Next()
	}
}



